//
//  Consume_ScreenViewController.m
//  JinFuThree
//
//  Created by 爱尚 on 2018/9/3.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "Consume_ScreenViewController.h"
#import "Consume_ScreenTableViewCell.h"
#import "Consume_ScreenCollectionViewCell.h"

@interface Consume_ScreenViewController ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)UITableView *leftTableView;
@property(nonatomic,strong)UICollectionView *rightCollectionView;
@property(nonatomic,strong)NSMutableArray *leftDataArr;

@end

@implementation Consume_ScreenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"筛选";
    self.view.backgroundColor = ListMaoBackgroundColor;
    [self initViews];
    [self bindleftData:@[@"手机",@"电动车",@"电脑",@"户外运动",@"家用家电"]];
}

-(void)bindleftData:(NSArray *)classifyData{
    
    if (classifyData.count != 0) {
        for (int i=0 ; i<classifyData.count; i++) {
            
            CellModel *model = [[CellModel alloc]init];
            model.userInfo = classifyData[i];
            if (i == 0) {
                model.isSelect = YES;
            }else{
               model.isSelect = NO;
            }
            
            model.className = NSStringFromClass([Consume_ScreenTableViewCell class]);
            [self.leftDataArr addObject:model];
        }
    }
    
    [self.leftTableView reloadData];
}

-(void)initViews{
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidthMao, 15)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    
    _leftTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    _leftTableView.delegate = self;
    _leftTableView.dataSource = self;
    _leftTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_leftTableView registerClass:[Consume_ScreenTableViewCell class] forCellReuseIdentifier:@"Consume_ScreenTableViewCell"];
    [self.view addSubview:_leftTableView];
    [_leftTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view.mas_top).offset(15);
        make.width.mas_offset(@(ScreenWidthMao/375*100));
        make.bottom.mas_equalTo(self.view);
    }];
    
    
    
    _rightCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:[[UICollectionViewFlowLayout alloc]init]];
    _rightCollectionView.delegate = self;
    _rightCollectionView.dataSource = self;
    _rightCollectionView.backgroundColor = [UIColor whiteColor];
    _rightCollectionView.showsVerticalScrollIndicator = NO;
    _rightCollectionView.showsHorizontalScrollIndicator = NO;
    [_rightCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerID"];
    [_rightCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerID"];
    [_rightCollectionView registerClass:[Consume_ScreenCollectionViewCell class] forCellWithReuseIdentifier:@"Consume_ScreenCollectionViewCell"];
    [self.view addSubview:_rightCollectionView];
    [_rightCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.leftTableView.mas_right).offset(5);
        make.top.mas_equalTo(self.leftTableView);
        make.bottom.mas_equalTo(self.view);
        make.right.mas_equalTo(self.view.mas_right).mas_offset(0);
    }];
    
}

#pragma mark -----------tableviewDelegate----------------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.leftDataArr.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    Consume_ScreenTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Consume_ScreenTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    CellModel *model = self.leftDataArr[indexPath.row];
    cell.titleLabel.text = model.userInfo;
    
    if (model.isSelect == YES) {
        cell.lineView.hidden = NO;
        cell.titleLabel.textColor = HexColor(0x5B85FD);
    }else{
        cell.lineView.hidden = YES;
        cell.titleLabel.textColor = HexColor(0x666666);
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    for (CellModel *model in self.leftDataArr) {
        model.isSelect = NO;
    }
    CellModel *model = self.leftDataArr[indexPath.row];
    model.isSelect = YES;
    [self.leftDataArr replaceObjectAtIndex:indexPath.row withObject:model];
    [self.leftTableView reloadData];
    
#pragma mark ----此处刷新右侧数据--------------
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -----------collectionViewDelegate-------------

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 9;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    Consume_ScreenCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Consume_ScreenCollectionViewCell" forIndexPath:indexPath];
    
    return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
   
    return CGSizeMake(((ScreenWidthMao-ScreenWidthMao/375*100-5)/3), ((ScreenWidthMao-ScreenWidthMao/375*100-5)/3));
    
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
    
    
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    
    
    return 0;
    
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    
    return 0;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    UICollectionReusableView *view = nil;
    
    if (kind == UICollectionElementKindSectionFooter) {
        view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerID" forIndexPath:indexPath];
        view.backgroundColor = RGBCOLOR(242, 242, 242,1);
        
        
        
        
    }else{
        
        
        view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerID" forIndexPath:indexPath];
        view.backgroundColor = RGBCOLOR(242, 242, 242,1);
        
        
    }
    
    return view;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    
    return CGSizeMake(ScreenWidthMao, 0);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    
    return CGSizeMake(ScreenWidthMao, 0);
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [self.navigationController popViewControllerAnimated:YES];
}
-(NSMutableArray *)leftDataArr{
    if (!_leftDataArr) {
        _leftDataArr = [[NSMutableArray alloc]init];
        
    }
    return _leftDataArr;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
